﻿namespace Audit.EntityFramework.Core.Samples.Infrastructure.CurrentUser;

public class CurrentUserContext(
    IHttpContextAccessor httpContextAccessor
) : ICurrentUser
{
    public bool IsAuthenticated =>
        httpContextAccessor
            .HttpContext?
            .User
            .Identity?
            .IsAuthenticated ??
        throw new ApplicationException("User context is unavailable");

    public int UserId =>
        httpContextAccessor
            .HttpContext?
            .User
            .GetUserId() ??
        throw new ApplicationException("User context is unavailable");

    public string UserName =>
        httpContextAccessor
            .HttpContext?
            .User
            .GetUserName() ??
        throw new ApplicationException("User context is unavailable");
}
